#include "stars.h"

Stars::Stars(QWidget *parent)
    : QDialog(parent)
{
    resize(640, 480);
    setStyleSheet("QDialog{background-color:black}");
    qsrand(quint32(time(nullptr)));
    for (int i = 0; i < 500; i ++ ) star[i] = new Star(this);
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &Stars::draw);
    timer->start(50);
}

Stars::~Stars()
{
}

void Stars::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPen dot;
    dot.setWidth(1);

    for (int i = 0; i < 500; i ++ )
    {
        dot.setColor(QColor(star[i]->color, star[i]->color, star[i]->color));

        dot.setColor(Qt::black);
        painter.setPen(dot);
        painter.drawPoint(star[i]->x, star[i]->y);
        star[i]->move();
        dot.setColor(QColor(star[i]->color, star[i]->color, star[i]->color));
        painter.setPen(dot);
        painter.drawPoint(star[i]->x, star[i]->y);
    }
}

void Stars::draw()
{
    update();
}

